<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('客户跟踪') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('事件发生类型')" prop="happenType">
        <dict-select
          v-model="queryParams.happenType"
          dictionary="lp_track_type"
          :placeholder="$t('事件发生类型')"
          clearable
        />
      </el-form-item>
      <el-form-item :label="$t('详细情况')" prop="remark">
        <el-input
          v-model="queryParams.remark"
          :placeholder="$t('详细情况')"
          clearable
        />
      </el-form-item>
      <el-form-item :label="$t('下一步计划')" prop="nextPlan">
        <el-input
          v-model="queryParams.nextPlan"
          :placeholder="$t('下一步计划')"
          clearable
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t("搜索") }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t("重置") }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['fund:lpTrack:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t("新增") }}</el-button>
      </el-col>
    </el-row>

    <!--    <el-table v-loading="loading" tooltip-effect="darkTable" :data="lpTrackList" border>-->
    <!--      <el-table-column :label="$t('序号')" type="index" align="center" width="50">-->
    <!--        <template slot-scope="scope">-->
    <!--          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}-->
    <!--        </template>-->
    <!--      </el-table-column>-->
    <!--      <el-table-column :label="$t('事件发生类型')" align="center" prop="happenType" width="200" show-overflow-tooltip />-->
    <!--      <el-table-column :label="$t('发生时间')" align="center" prop="happenDate" width="120">-->
    <!--        <template slot-scope="scope">-->
    <!--          <span>{{ parseTime(scope.row.happenDate) }}</span>-->
    <!--        </template>-->
    <!--      </el-table-column>-->
    <!--      <el-table-column :label="$t('详细情况')" align="center" prop="remark" show-overflow-tooltip />-->
    <!--      <el-table-column :label="$t('下一步计划')" align="center" prop="nextPlan" show-overflow-tooltip />-->
    <!--      <el-table-column :label="$t('更新人')" align="center" width="120">-->
    <!--        <template slot-scope="scope">-->
    <!--          <span>{{ scope.row.updateBy.nickName }}</span>-->
    <!--        </template>-->
    <!--      </el-table-column>-->
    <!--      <el-table-column :label="$t('更新时间')" align="center" prop="updateTime" width="120">-->
    <!--        <template slot-scope="scope">-->
    <!--          <span>{{ parseTime(scope.row.updateTime) }}</span>-->
    <!--        </template>-->
    <!--      </el-table-column>-->
    <!--      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="200">-->
    <!--        <template slot-scope="scope">-->
    <!--          <el-button-->
    <!--            v-hasPermi="['fund:lpTrack:edit']"-->
    <!--            size="small"-->
    <!--            type="text"-->
    <!--            icon="el-icon-edit"-->
    <!--            @click="updateHandle(scope.row)"-->
    <!--          >{{ $t('修改') }}</el-button>-->
    <!--          <el-button-->
    <!--            v-hasPermi="['fund:lpTrack:remove']"-->
    <!--            size="small"-->
    <!--            type="text"-->
    <!--            icon="el-icon-delete"-->
    <!--            @click="deleteHandle(scope.row)"-->
    <!--          >{{ $t('删除') }}</el-button>-->
    <!--        </template>-->
    <!--      </el-table-column>-->
    <!--    </el-table>-->

    <div class="dealTrack">
      <ul>
        <li v-for="info in lpTrackList" :key="info.id">
          <p class="time">{{ parseTime(info.happenDate) }}</p>
          <div class="content">
            <div class="main" @click="updateHandle(info)">
              <div class="top">
                <span class="nickName">{{ info.updateBy.nickName }}</span>
                <span class="track">{{ trackModeFormat(info) }}</span>
                <!--                <span class="type">{{ itemTypeFormat(info) }}</span>-->
              </div>
              <div class="otherPeople"><span>对方人员</span>: <p>{{ info.otherPeople ? info.otherPeople : '-' }}</p></div>
              <div class="otherPeople"><span>我方人员</span>: <p>{{ info.ourPerson ? info.ourPerson : '-' }}</p></div>
              <div class="otherPeople"><span>事件发生类型</span>: <p>{{ info.happenType ? formatHappenType(info.happenType) : '-' }}</p></div>
              <div class="otherPeople"><span>详细情况</span>:<div class="richTextField" v-html="info.remark" /></div>
              <div class="otherPeople"><span>下步计划</span>:<div class="richTextField" v-html="info.nextPlan" /></div>
              <div class="otherFile"><span>附件</span>:
                <template v-if="info.fileList.length>0">
                  <div class="file">
                    <p v-for="file in info.fileList" :key="file.id" class="click_file" @click.stop="preview(file.id)"> {{ file.name }} </p>
                  </div>
                </template>
                <templet v-else>-</templet>
              </div>
            </div>
            <div class="btn">
              <el-button
                v-hasPermi="['fund:lpTrack:edit']"
                size="small"
                type="text"
                icon="el-icon-edit"
                @click="updateHandle(info)"
              />
              <el-button
                v-hasPermi="['fund:lpTrack:remove']"
                size="small"
                type="text"
                icon="el-icon-delete"
                @click="deleteHandle(info)"
              />
            </div>
          </div>
        </li>
      </ul>
    </div>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改客户跟踪对话框 -->
    <el-dialog :title="title" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <lpTrackForm ref="lpTrackForm" :lp-id="lpId" />
    </el-dialog>
    <OnlinePreview ref="OnlinePreview" :preview-tit="previewTit" />
  </div>
</template>

<script>
import { listLpTrack, delLpTrack, exportLpTrack } from '@/api/fund/lpTrack/lpTrack'
import lpTrackForm from './lpTrackForm.vue'
export default {
    components: {
        lpTrackForm
    },
  props: {
      lpId: {
        type: String,
        default: undefined
      }
  },
  data() {
      return {
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          // 客户跟踪表格数据
          lpTrackList: [],
          // 事项类型 字典item_type字典
          itemTypeOptions: [],
          happenTypeOptions: [],
          // 跟踪方式 字典track_mode字典
          trackModeOptions: [],
          // 弹出层标题
          title: '',
          // 是否显示弹出层
          formOpen: false,
          // 查询参数
          queryParams: {
              lpId: this.$route.query.lpId,
              remark: undefined,
              nextPlan: undefined,
              pageNum: 1,
              pageSize: 10
          },
          // 表单参数
          form: {},
          // 表单校验
          rules: {
            happenType: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
            happenDate: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }]
          },
          previewTit: ''
      }
  },
  created() {
      this.getList()
      this.getDicts('item_type').then(response => {
        this.itemTypeOptions = response.data
      })
      this.getDicts('track_mode').then(response => {
        this.trackModeOptions = response.data
      })
      this.getDicts('lp_track_type').then(response => {
        this.happenTypeOptions = response.data
      })
  },
  methods: {
    formatHappenType(value) {
      var val = this.selectDictLabel(this.happenTypeOptions, value)
      if (!val || val === '') {
        val = value
      }
      return val
    },
    formatText(text) {
      if (text) {
        var val = text.replace(/\n/g, '</li><li>')
        return '<ul class="ul_style"><li>' + val + '</li></ul>'
      } else {
        return text
      }
    },
    /** 查询客户跟踪列表 */
    getList() {
        this.loading = true
        this.queryParams.lpId = this.$route.query.lpId || this.lpId
        listLpTrack(this.queryParams).then(response => {
            this.lpTrackList = response.rows
            this.total = response.total
            this.loading = false
        })
    },
    // 事项类型 字典item_type字典翻译
    itemTypeFormat(row) {
      return this.selectDictLabel(this.itemTypeOptions, row.itemType)
    },
    // 跟踪方式 字典track_mode字典翻译
    trackModeFormat(row) {
      return this.selectDictLabel(this.trackModeOptions, row.trackMode)
    },

    // 表单重置
    reset() {
        this.form = {
            id: undefined,
            lpId: this.$route.query.lpId,
            happenType: undefined,
            happenDate: undefined,
            createBy: undefined,
            createTime: undefined,
            updateBy: undefined,
            updateTime: undefined,
            delFlag: undefined,
            remark: undefined
        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
        this.formOpen = true
        this.title = this.$t('客户跟踪')
        this.$nextTick(() => {
            this.$refs.lpTrackForm.init(null)
        })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
        this.formOpen = true
        this.title = this.$t('客户跟踪')
        this.$nextTick(() => {
            // 调用form页面的 init 方法初始化数据
            this.$refs.lpTrackForm.init(row)
        })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(function() {
            return delLpTrack(row.id)
        }).then(() => {
            this.getList()
            this.msgSuccess(this.$t('删除成功'))
            this.$parent.$parent.getList()
        }).catch(function() {
        })
    },
    /** 导出按钮操作 */
    exportHandle() {
        const queryParams = this.queryParams
        this.$confirm(this.$t('是否确认导出?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(function() {
            return exportLpTrack(queryParams)
        }).then(response => {
            this.download(response.msg)
        }).catch(function() {
        })
    },
     preview(fileId) {
       this.$refs.OnlinePreview.onlinePreviewFile(fileId, 'view')
    }
  }
}
</script>
<style lang="scss" scoped>
.otherFile{
  color: rgba(0, 0, 0, 0.8);
  font-size: 13px;
  display: flex;
  span{
    color: rgba(0, 0, 0, 0.65);
    white-space: nowrap;
  }
  .file{
    margin-left: 10px;
    p{
      margin:0px;
      line-height: 20px;
      margin-bottom: 5px;
      &:last-child{
        margin: 0;
      }
    }
  }

}
 .click_file{
  color:#409EFF;
  cursor: pointer;
  display: block !important;
}

.dealTrack{
  // box-shadow: 0 2px 12px 0 #eee;
  border-radius: 10px;
  margin: 10px 0;
  padding: 25px 25px 25px 150px;
  p{
    margin: 0;
  }
  ul{
    li{
      position: relative;
      border-left: 1px solid #E1E2E8;
      padding-left: 30px;
      padding-bottom: 20px;
      .time{
        position: absolute;
        left: -100px;
        font-size: 14px;
        top: calc(50% - 12px);
      }
      .top{
        display: flex;
        align-items: center;
        column-gap: 10px;
        margin-bottom: 10px;
        .nickName{
          font-weight: bold;
          font-size: 14px;
        }
        .track{
          background: #9288D0;
          color: #fff;
          font-size: 13px;
          border-radius: 10px;
          padding: 3px 6px;
        }
        .type{
          background: #59D6CD;
          color: #fff;
          font-size: 13px;
          border-radius: 10px;
          padding: 3px 6px;
        }
      }
      .otherPeople{
        color: rgba(0, 0, 0, 0.8);
        font-size: 13px;
        display: flex;
        flex-wrap: wrap;
        span{
          color: rgba(0, 0, 0, 0.65);
          white-space: nowrap;
        }
        p{
          margin-left: 5px;
          line-height: 16px;
          overflow-wrap: anywhere;
        }
        div{
          width: 100%;
        }
      }
      .details{
        color: #F4A9A2;
      }
      .main{
        background-color: #F4F7F6;
        border-radius: 10px;
        padding: 15px;
        width: 70%;
        flex: 1;
        position: relative;
        &::before{
          position: absolute;
          content: '';
          width:0;
          height:0;
          border-top:10px solid transparent;
          border-bottom:10px solid transparent;
          border-right:10px solid #F4F7F6;
          left: -10px;
          top: calc(50% - 5px);
        }
        div{
          margin-bottom: 10px;
          line-height: 16px;
          &:last-child{
            margin-bottom: 0;
          }
        }
      }
      .content{
        display: flex;
        align-items: center;
        .btn{
          width: 70px;
          text-align: center;
        }
      }
      &::before{
        position: absolute;
        content: '';
        width: 10px;
        height: 10px;
        border-radius: 50%;
        background: #fff;
        border: 1px solid #E1E2E8;
        left: -6px;
        top: calc(50% - 10px);
      }
    }
  }
}
</style>
